#!/bin/env python
import subprocess


def nslookup(domain):
    try:
        cmd = 'nslookup ' + domain
        print(cmd)
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE, shell=True)
        return p.stdout.read()
    except Exception as e:
        return str(e)


def dig(domain, **kwargs):
    try:
        cmd = 'dig +trace ' + domain
        print(cmd)
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE, shell=True)
        return p.stdout.read()
    except Exception as e:
        return str(e)


if __name__ == "__main__":
    print(nslookup('www.baidu.com'))
    print(dig('www.baidu.com'))
